package service

import (
	"context"
	"fmt"
	__ "video/video-srv/desic/proto"
	"video/video-srv/handler/models"
)

type Server struct {
	__.UnimplementedVideoServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) VideoAdd(_ context.Context, in *__.VideoAddReq) (*__.VideoAddResp, error) {
	video := models.Video{
		VideoTitle: in.VideoTitle,
		Static:     in.Static,
		Address:    in.Address,
	}
	if err := models.VideoAdd(&video); err != nil {
		return nil, fmt.Errorf("添加失败")
	}
	return &__.VideoAddResp{
		Id: int64(video.ID),
	}, nil
}
func (s *Server) TvDramaAdd(_ context.Context, in *__.TvDramaAddReq) (*__.TvDramaAddResp, error) {
	tvDrama := models.TvDrama{
		EpisodeID: int(in.EpisodeId),
		TitlePlay: in.TitlePlay,
		Static:    in.Static,
		Producer:  in.Producer,
	}
	if err := models.TvDramaAdd(&tvDrama); err != nil {
		return nil, fmt.Errorf("电视剧添加失败")
	}
	return &__.TvDramaAddResp{
		Id: int64(tvDrama.ID),
	}, nil
}
func (s *Server) ReviewAdd(_ context.Context, in *__.ReviewAddReq) (*__.ReviewAddResp, error) {
	str := ""
	if in.Static != "1" {
		str = "待审核"
	}
	if in.Static != "2" {
		str = "审核中"
	}
	if in.Static != "3" {
		str = "通过"
	}
	if in.Static != "4" {
		str = "驳回"
	}
	review := models.Review{
		VideoId: int(in.VideoId),
		Static:  str,
		Opinion: in.Opinion,
	}
	if err := models.ReviewAdd(&review); err != nil {
		return nil, fmt.Errorf("添加失败")
	}
	return &__.ReviewAddResp{
		Id: int64(review.ID),
	}, nil
}
func (s *Server) VideoVipAdd(_ context.Context, in *__.VideoVipAddReq) (*__.VideoVipAddResp, error) {
	str := ""
	if in.Permission == "1" {
		str = "未登录"
	}
	if in.Permission == "2" {
		str = "非VIP"
	}
	if in.Permission == "3" {
		str = "VIP有效期内"
	}
	if in.Permission == "4" {
		str = "VIP已过期"
	}
	VideoVip := models.VideoVip{
		UserId:     int(in.UserId),
		Expire:     in.Expire,
		Permission: str,
	}
	if err := models.VideoVipAdd(&VideoVip); err != nil {
		return nil, fmt.Errorf("添加失败")
	}
	return &__.VideoVipAddResp{
		Id: int64(VideoVip.ID),
	}, nil
}
